package microcredit.gui.editor.member;

import java.awt.Color;

import javax.swing.JScrollPane;

import microcredit.gui.editor.AbstractEditorForm;
import microcredit.gui.table.BeanTable;
import microcredit.gui.table.TableFactory;
import microcredit.model.Member;
import microcredit.model.MemberStatusHistory;
import net.miginfocom.swing.MigLayout;

public class MemberStatusHistoryForm extends AbstractEditorForm<Member> {
	
	private JScrollPane scrollPane;
	private BeanTable<MemberStatusHistory> table;
	
	public MemberStatusHistoryForm() {
		setLayout(new MigLayout("", "[][grow]", "[][grow]"));
		add(getScrollPane(), "cell 1 1,grow");
		setTitle("Status history");
	}

	@Override
	public void apply(Member e) throws Throwable {
		getTable().load(e.getMemberStatusHistories());
	}

	@Override
	public Member receive(Member e) throws Throwable {
		return e;
	}

	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setViewportView(getTable());
		}
		return scrollPane;
	}
	
	private BeanTable<MemberStatusHistory> getTable() {
		if (table == null) {
			table = TableFactory.create(MemberStatusHistory.class);
			table.setLastLineColor(Color.decode("#baff7d"));
			table.setRowSorter(null);
		}
		return table;
	}
	
}
